﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;

namespace _039
{
    internal class Program
    {
        static void Main(string[] args)
        {
            TestUserDefineException test = new TestUserDefineException();
            try
            {
                test.validate(12);
            }
            catch(InvalidAgeException e)
            {
                Console.WriteLine("InvalidAgeException:{0}",e);
            }
            Console.WriteLine("其他代码");
            Console.ReadKey();
        }
    }
    public class InvalidAgeException:ApplicationException
    {
        public InvalidAgeException(string message) : base(message)
        {
        }
    }
    public class  TestUserDefineException
    {
        public void validate(int age)
        {
            if(age<18)
            {
                throw (new InvalidAgeException("sorry,age must be greater than 18"));
            }
        }
    }
}
